{extend name="default/base/base_seller" /}
{block name="seller_main"}
<style>
    .courseware-item{padding:5px 10px;background:#cae7ff;color:#165ba5;margin-right:10px;}
    .courseware-item:hover{color:#165ba5}
    .courseware-item .iconfont{padding-left:3px;font-size: 12px;}
</style>
<div class="dssc-form-default">
    <form method="post" name="goodscourses_form" id="goodscourses_form" enctype="multipart/form-data">
        <dl>
            <dt><i class="required">*</i>{$Think.lang.goodscourses_name}{$Think.lang.ds_colon}</dt>
            <dd>
                <input type="text" class="w600 text" name="goodscourses_name" value="{$goodscourses.goodscourses_name|default=''}" /><span></span>
            </dd>
        </dl>
        <dl>
            <dt>课程目录{$Think.lang.ds_colon}</dt>
            <dd>
                <input type="text" class="w300 text" readonly="" id="goodscourses_class_name" name="goodscourses_class_name" value="{$goodscourses.goodscourses_class_name|default=''}" {if !isset($goodscourses.goodscourses_class_id) || !$goodscourses.goodscourses_class_id}style="display: none"{/if} />
                       <input type="hidden" id="goodscourses_class_id" name="goodscourses_class_id" value="{$goodscourses.goodscourses_class_id|default=''}" />
                <a class="dssc-btn dssc-btn-orange" id="cancle_goodscourses" {if !isset($goodscourses.goodscourses_class_id) || !$goodscourses.goodscourses_class_id}style="display: none"{/if} onclick="cancleCourseClas()">取消目录</a>
                <a class="dssc-btn" ds_type="dialog" dialog_width="480" dialog_title="选择目录" dialog_id="select_directory" uri="{:url('Sellergoodsonline/course_class_list',['goods_id'=>$Request.param.goods_id])}" {if isset($goodscourses.goodscourses_class_id) && $goodscourses.goodscourses_class_id}style="display: none"{/if} id="select_directory">选择目录</a>
            </dd>
        </dl>
        <dl>
            <dt>{$Think.lang.goodscourses_sort}{$Think.lang.ds_colon}</dt>
            <dd>
                <input type="text" class="w50 text" name="goodscourses_sort" value="{$goodscourses.goodscourses_sort|default='255'}"/>
            </dd>
        </dl>
        <dl>
            <dt>{$Think.lang.goodscourses_free}{$Think.lang.ds_colon}</dt>
            <dd>
                <label><input type="radio" name="goodscourses_free" value="1" {if $goodscourses.goodscourses_free == 1}checked="checked"{/if}/>{$Think.lang.store_create_yes}</label>
                <label><input type="radio" name="goodscourses_free" value="0" {if $goodscourses.goodscourses_free == 0 }checked="checked"{/if} />{$Think.lang.store_create_no}</label>
            </dd>
        </dl>
        <dl>
            <dt>试看时长{$Think.lang.ds_colon}</dt>
            <dd>
                <input type="text" class="w50 text" name="goodscourses_exper" value="{$goodscourses.goodscourses_exper|default=''}"/> 秒（仅阿里云/腾讯云视频支持试看，腾讯云试看时长应不小于30秒）
            </dd>
        </dl>
        <dl>
            <dt>{$Think.lang.store_goods_video}{$Think.lang.ds_colon}</dt>
            <dd>
                <div class="dssc-goods-default-pic">
                    <div class="goodspic-uplaod">
                        <div class="upload-thumb"> 
                            <video controls="" height="400" width="400" dstype="goodscourses_url" src="{if isset($goodscourses.goodscourses_url)}{$goodscourses.goodscourses_url|raw}{/if}"/>
                        </div>
                        <input type="hidden" name="videoupload_id" id="videoupload_id" dstype="videoupload_id" value="{$goodscourses.videoupload_id|default=''}" />
                        <span></span>
                        
                        <div class="handle">
                            <div dstype="upload_type_cloud" class="upload_type dssc-upload-btn"> <a href="javascript:void(0);"><span>
                                        <input type="file" hidefocus="true" size="1" class="input-file" name="goodsvideo" id="goodsvideo">
                                    </span>
                                    <p><i class="iconfont">&#xe733;</i>{$Think.lang.store_goods_video_upload}</p>
                                </a> </div>
                            <div dstype="upload_type_local" class="upload_type dssc-upload-btn" style='display:none'> <a href="javascript:void(0);"><span>
                                        <input type="file" hidefocus="true" size="1" class="input-file" name="goodsvideo2" id="goodsvideo2">
                                    </span>
                                    <p><i class="iconfont">&#xe733;</i>{$Think.lang.store_goods_video_upload}</p>
                                </a> </div>
                            <span dstype="upload_type_link" class='upload_type' style='display:none;'>
                                <input type="text" class="w300 text" id="video_url"><div class="dssc-upload-btn" onclick="submitVideo()"> <a href="javascript:void(0);">
                                    <p><i class="iconfont">&#xe733;</i>{$Think.lang.store_goods_video_upload}</p>
                                </a> </div>
                            </span>
                            
                            <a class="dssc-btn" dstype="show_video"><i class="iconfont">&#xe72a;</i>{$Think.lang.store_goods_video_select}</a> <a href="javascript:void(0);" dstype="del_goods_video_list" class="dssc-btn" style="display: none;"><i class="iconfont">&#xe67a;</i>{$Think.lang.store_goods_video_close}</a></div>
                        <p class="hint">视频将上传到<span id='upload_type_text'>云服务器</span>，请点击 <a href="javascript:setUploadType('cloud','云服务器');">云服务器</a>/<a href="javascript:setUploadType('local','本地服务器');">本地服务器</a>/<a href="javascript:setUploadType('link','外部链接');">外部链接</a> 切换</p>    
                        <p class="hint" style="margin-top:0">如果视频不能正常播放，请将视频转换为H264编码的MP4格式</p>
                    </div>
                </div>
                <div id="goods_video_list"></div>
            </dd>
        </dl>
        <!--{if $Think.config.ds_config.baidu_pan_id}-->
        <dl>
            <dt>课程课件{$Think.lang.ds_colon}</dt>
            <dd>
                <div id='check_courseware'>
                    <!--{if isset($goodscourses.baidu_pan_fsids)}-->
                    <!--{foreach name='goodscourses.baidu_pan_fsids' item='file_name' key='file_id'}-->
                    <a class="courseware-item" data-id="{$file_id}" href="javascript:delCheck('{$file_id}')">{$file_name}<span class="iconfont">&#xe6e6;</span><input type="hidden" name="pand_id[{$file_id}]" value="{$file_name}"></a>
                    <!--{/foreach}-->
                    <!--{/if}-->
                </div>
                <!--{if $if_baidu_pan}-->
                <div class="dssc-goods-default-pic">
                    <div class="goodspic-uplaod">
                        <div class="handle">
                            <div class="dssc-upload-btn"> <a href="javascript:void(0)"><span>
                                        <input type="file" hidefocus="true" size="1" class="input-file" name="courseware" id="courseware">
                                    </span>
                                    <p><i class="iconfont">&#xe733;</i>课件上传</p>
                                </a> </div>
                            <a class="dssc-btn" dstype="show_pan"><i class="iconfont">&#xe72a;</i>从网盘中选择</a> <a href="javascript:void(0);" dstype="del_courseware_list" class="dssc-btn" style="display: none;"><i class="iconfont">&#xe67a;</i>关闭网盘</a></div>
                    </div>
                </div>
                <input type='hidden' name='courseware_change' id='courseware_change' value='0'>
                <div id="courseware_list"></div>
                <!--{else}-->
                <a class="dssc-btn" href="http://openapi.baidu.com/oauth/2.0/authorize?response_type=code&client_id={$Think.config.ds_config.baidu_pan_api_key}&redirect_uri={$baidu_pan_url}&scope=basic,netdisk&display=tv&qrcode=1" target="_blank">绑定网盘账号</a>
                <!--{/if}-->
            </dd>
        </dl>
        <!--{/if}-->
        <div class="bottom">
            <input type="submit" class="submit" value="{$Think.lang.ds_submit}" />
        </div>
    </form>
</div>
<script src="{$Think.PLUGINS_SITE_ROOT}/jquery.ajaxContent.pack.js"></script>
<script src="{$Think.PLUGINS_SITE_ROOT}/spark-md5.min.js"></script>
{if $Think.config.ds_config.video_type=='tencent'}
<script src="//cdn.bootcss.com/axios/0.18.0/axios.js"></script>
<script src="//unpkg.com/vod-js-sdk-v6"></script>
{/if}
{if $Think.config.ds_config.video_type=='aliyun'}
<script src="{$Think.PLUGINS_SITE_ROOT}/aliyun-upload-sdk-1.5.0/aliyun-upload-sdk-1.5.0.min.js"></script>
<script src="{$Think.PLUGINS_SITE_ROOT}/aliyun-upload-sdk-1.5.0/lib/es6-promise.min.js"></script>
<script src="{$Think.PLUGINS_SITE_ROOT}/aliyun-upload-sdk-1.5.0/lib/aliyun-oss-sdk-5.3.1.min.js"></script>
{/if}
<script type="text/javascript">

    var total_cloud_space={$total_cloud_space};
    var total_local_space={$total_local_space};
    var cloud_limit={$cloud_limit};
    var local_limit={$local_limit};

    var index
    var fileInfo
    var chunkLength
    $(document).ready(function () {

        /*上传到本地服务器开始*/
        $('#goodsvideo2').change(function(e){
            var myfile = e.target.files[0];
            fileInfo=myfile
            if(local_limit && (total_local_space+fileInfo.size)>local_limit*1024*1024){
                layer.msg('您的视频已超出所属店铺等级本地视频空间限制'+local_limit+'MB')
                return
            }
            
        // 定义文件标识符  
        var unique_tag = SparkMD5.ArrayBuffer.hash(myfile);
        // 数据切片
        var chunks = fileSlice(myfile);
        chunkLength=chunks.length
        // 发送分割数据段
            index = layer.msg('0%', {
                icon: 16
            })
        sendChunk(unique_tag, chunks);

        })
        

 
   function fileSlice(file, chunkSize = 1024*1024*2){
        // 1.初始化数据
        var totalSize = file.size;
        var start = 0;
        var end = start + chunkSize;
        var chunks = [];
        // 2.使用bolb提供的slice方法切片
        while(start < totalSize){
            var chunk = file.slice(start, end);
            chunks.push(chunk);
            start = end;
            end += chunkSize;
        }
        // 3.返回切片组chunk[]
        return chunks;
    }
 
    function sendChunk(unique_tag, chunks){
        // 逐个提交
        chunks.forEach(function(chunk, index){
            var formData = new FormData();
            //唯一标识
            formData.append('unique_tag', unique_tag);
            //文件
            formData.append('file', chunk);
            //片的总数
            formData.append('total_num', chunks.length);
            //当前传输的片数
            formData.append('now_num', index+1);
        
            $.ajax({
                type: "POST",
                url: "{:url('Sellervideo/upload')}",
                dataType: 'json',
                data: formData,
                contentType: false,
                processData: false,
                success: function(data){
                    if (data.code == 10000) {
                            index = layer.msg(Math.round((chunks.length-chunkLength)/chunks.length*100)+'%', {
                                icon: 16
                            })
                        chunkLength--
                        if(chunkLength<=0){
                            $.ajax({
                                type: "POST",
                                url: "{:url('Sellervideo/merge')}",
                                dataType: 'json',
                                data: formData,
                                contentType: false,
                                processData: false,
                                success: function(data){
                                    if (data.code == 10000) {
                                        layer.close(index)
                                        save_video({
                                            video_type: 'local',
                                            file_name:fileInfo.name,
                                            size:fileInfo.size,
                                            url: data.result.name,
                                            type: "{$Request.param.type}",
                                            item_id: "{$Request.param.item_id}"
                                        })
                                    } else {
                                        layer.msg(data.message)
                                        layer.close(index)
                                    }
                                }
                            })
                        }
                    } else {
                        layer.msg(data.message)
                        layer.close(index)
                    }

                }
            })
        })
    }
 
        /*上传到本地服务器结束*/
        
        /*百度云盘分片上传开始*/
        $("#courseware").change(function (e) {
            var blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice,
                    file = e.target.files[0],
                    chunkSize = 4 * 1024 * 1024, // Read in chunks of 20GB
                    chunks = Math.ceil(file.size / chunkSize),
                    currentChunk = 0,
                    spark = new SparkMD5.ArrayBuffer(),
                    fileReader = new FileReader(),
                    file_index=0,
                    file_size = file.size,
                    block_list = [],
                    file_list = []
            index = layer.msg('0%', {
                icon: 16
            })
            fileReader.onload = function (e) {
                console.log('read chunk nr', currentChunk + 1, 'of', chunks);
                spark.append(e.target.result);                   // Append array buffer
                currentChunk++;
                block_list.push(spark.end())
                file_list.push(e.target.result)
                if (currentChunk < chunks) {
                    loadNext();
                } else {
                    console.log('finished loading');
                    var path = '/apps/{$Think.config.ds_config.baidu_pan_app_name}/{$goods.goods_name}/' + file.name

                    $.post("{:url('SellerCourseware/baidu_pan_precreate')}", {isdir: 0, autoinit: 1, path: path, block_list: block_list, size: file_size},
                            function (data) {
                                if (data.code == 10000) {
                                    var partseq_list = data.result.block_list
                                    if (!partseq_list.length) {
                                        partseq_list = [0]
                                    }
                                    block_list = []
                                    for (var i in partseq_list) {
                                        upload_file(path, data.result.uploadid, i, file_list[i])
                                    }
                                } else {
                                    layer.msg(data.message)
                                    layer.close(index)
                                }

                            },
                            'json');
                }
            };

            fileReader.onerror = function () {
                console.warn('oops, something went wrong.');
                layer.close(index)
            };

            function loadNext() {
                var start = currentChunk * chunkSize,
                        end = ((start + chunkSize) >= file_size) ? file_size : start + chunkSize;

                fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));
            }

            loadNext();



            function upload_file(path, uploadid, partseq, file) {
                var fordata = new FormData(); // 生成文件对象
                fordata.append('file', new File([file], 'file')); // 添加
                $.ajax({ url: "{:url('SellerCourseware/baidu_pan_upload')}?type=tmpfile&path=" + path + "&uploadid=" + uploadid + "&partseq=" + partseq, type: 'post', dataType: 'json', processData: false, contentType: false, data: fordata,
                    success: function (data) {
                        if (data.code == 10000) {
                            file_index++
                            layer.close(index)
                            index = layer.msg(Math.round(file_index/file_list.length*100)+'%', {
                                icon: 16
                            })
                            block_list.push({seq: partseq, md5: data.result.md5})
                            if (file_index >= file_list.length) {
                                block_list.sort(function (a, b) {
                                    return a.seq - b.seq
                                })
                                var temp = []
                                for (var i in block_list) {
                                    temp.push(block_list[i].md5)
                                }
                                create_file(path, uploadid, temp)
                            }
                        } else {
                            layer.msg(data.message)
                            layer.close(index)
                        }

                    }});
            }

            function create_file(path, uploadid, mblock_list) {
                $.post("{:url('SellerCourseware/baidu_pan_create')}", {isdir: 0, path: path, size: file_size, uploadid: uploadid, block_list: mblock_list},
                        function (data) {
                            if (data.code == 10000) {
                                $('*[dstype=show_pan]').click()
                                layer.close(index)
                            } else {
                                layer.msg(data.message)
                                layer.close(index)
                            }
                        }, 'json');
            }
        })

        /*百度云盘分片上传结束*/


        /* 商品视频ajax上传 */
        $('#goodsvideo').change(function (event) {
            /*{if ($Think.config.ds_config.video_type=='tencent' && !$Think.config.ds_config.vod_tencent_appid) || ($Think.config.ds_config.video_type=='aliyun' && !$Think.config.ds_config.aliyun_user_id)}*/
            layer.msg('请先联系管理员完成视频上传配置')
            return
            /*{/if}*/
            fileInfo=event.target.files[0]
            if(cloud_limit && (total_cloud_space+fileInfo.size)>cloud_limit*1024*1024){
                layer.msg('您的视频已超出所属店铺等级云视频空间限制'+cloud_limit+'MB')
                return
            }
            index = layer.msg('0%', {
                icon: 16
            })
            /*{if $Think.config.ds_config.video_type=='tencent'}*/
            const tcVod = new TcVod.default({
                getSignature: getSignature
            })
            const uploader = tcVod.upload({
                videoFile: fileInfo // 媒体文件（视频或音频或图片），类型为 File
            })
            $('#goodsvideo').val('')
            uploader.on('media_progress',
                    function (info) {
                        layer.close(index)
                        index = layer.msg(parseInt(info.percent * 100) + '%', {
                            icon: 16
                        })
                    })
            uploader.done().then(function (doneResult) {
                layer.close(index)
                save_video({
                    video_type: 'tencent',
                    file_name:fileInfo.name,
                    size:fileInfo.size,
                    file_id: doneResult.fileId,
                    url: doneResult.video.url,
                    type: "{$Request.param.type}",
                    item_id: "{$Request.param.item_id}"
                })
            }).catch(function (err) {
                layer.msg(err.message)
            })
            /*{/if}*/
            /*{if $Think.config.ds_config.video_type=='aliyun'}*/
            var userData = '{"Vod":{}}'
            uploader.addFile(fileInfo, null, null, null, userData)
            uploader.startUpload()
            /*{/if}*/
        });
        /* ajax打开视频库 */
        $('a[dstype="show_video"]').attr('href', "{:url('Sellervideo/video_list')}").unbind().ajaxContent({
            event: 'click',
            //mouseover
            loaderType: "img",
            loadingMsg: HOMESITEROOT + "/images/loading.gif",
            target: '#goods_video_list'
        }).click(function () {
            $(this).hide();
            $('a[dstype="del_goods_video_list"]').show();
        });
        $('a[dstype="del_goods_video_list"]').unbind().click(function () {
            $('#goods_video_list').html('');
            $(this).hide();
            $('a[dstype="show_video"]').show();
        });

        /* ajax打开网盘 */
        $('a[dstype="show_pan"]').attr('href', "{:url('SellerCourseware/baidu_pan_file')}").unbind().ajaxContent({
            event: 'click',
            //mouseover
            loaderType: "img",
            loadingMsg: HOMESITEROOT + "/images/loading.gif",
            target: '#courseware_list'
        }).click(function () {
            $(this).hide();
            $('a[dstype="del_courseware_list"]').show();
        });
        $('a[dstype="del_courseware_list"]').unbind().click(function () {
            $('#courseware_list').html('');
            $(this).hide();
            $('a[dstype="show_pan"]').show();
        });
        //页面输入内容验证
        $('#goodscourses_form').validate({
            errorPlacement: function (error, element) {
                var error_td = element.parent('dd').children('span');
                error_td.append(error);
            },
            submitHandler: function (form) {
                ds_ajaxpost('goodscourses_form', 'url', "{:url('Sellergoodsonline/list_courses',['goods_id'=>$Request.param.goods_id])}")
            },
            rules: {
                goodscourses_name: {
                    required: true,
                    maxlength: 50
                },
                videoupload_id: {
                    required: true
                }
            },
            messages: {
                goodscourses_name: {
                    required: '<i class="iconfont">&#xe64c;</i>{$Think.lang.goodscourses_name_null}',
                    maxlength: '<i class="iconfont">&#xe64c;</i>{$Think.lang.goodscourses_name_max}'
                },
                videoupload_id: {
                    required: '<i class="iconfont">&#xe64c;</i>{$Think.lang.goodscourses_url_null}',
                }
            }
        });
    });
    /* 插入商品视频 */
    function insert_video(id, src) {
        $('input[dstype="videoupload_id"]').val(id);
        $('video[dstype="goodscourses_url"]').attr('src', src);
    }
    /* 更换上传 */
    function setUploadType(id,text){
        $('.upload_type').hide()
        $('*[dstype=upload_type_'+id+']').show()
        $('#upload_type_text').text(text)
    }
    /* 视频外链 */
        function submitVideo(){
            var url=$('#video_url').val()
            if(!url){
                layer.msg('请填写视频链接')
                return
            }
            save_video({
                    video_type: 'link',
                    url: url,
                    type: "{$Request.param.type}",
                    item_id: "{$Request.param.item_id}"
                })
        }
    /* 保存视频 */
    function save_video(param) {
        //上传成功更新数据库
        $.post("{:url('Sellervideo/saveVideo')}", param,
                function (data) {
                    if (data.code == '10000') {
                        total_cloud_space=data.result.total_cloud_space
                        total_local_space=data.result.total_local_space
                        cloud_limit=data.result.cloud_limit
                        local_limit=data.result.local_limit
                        $('a[dstype="show_video"]').click()
                        layer.msg("{$Think.lang.store_goods_video_verify}")
                    } else {
                        layer.msg(data.message)
                    }
                },
                'json');
    }
    /*{if $Think.config.ds_config.video_type=='tencent'}*/
    function getSignature() {
        return axios.post("{:url('Sellervideo/getTencentSign')}", JSON.stringify({})).then(function (response) {
            return response.data.result
        })
    }
    /*{/if}*/
    /*{if $Think.config.ds_config.video_type=='aliyun'}*/
    //兼容IE11
    if (!FileReader.prototype.readAsBinaryString) {
        FileReader.prototype.readAsBinaryString = function (fileData) {
            var binary = "";
            var pt = this;
            var reader = new FileReader();
            reader.onload = function (e) {
                var bytes = new Uint8Array(reader.result);
                var length = bytes.byteLength;
                for (var i = 0; i < length; i++) {
                    binary += String.fromCharCode(bytes[i]);
                }
                //pt.result  - readonly so assign binary
                pt.content = binary;
                pt.onload()
            }
            reader.readAsArrayBuffer(fileData);
        }
    }
    var uploader = null
    /** 
     * 创建一个上传对象
     * 使用 UploadAuth 上传方式
     */
    var uploader = new AliyunUpload.Vod({
        userId: '{$Think.config.ds_config.aliyun_user_id}',
        // 添加文件成功
        addFileSuccess: function (uploadInfo) {
        },
        // 开始上传
        onUploadstarted: function (uploadInfo) {
            // 如果是 UploadAuth 上传方式, 需要调用 uploader.setUploadAuthAndAddress 方法
            // 如果是 UploadAuth 上传方式, 需要根据 uploadInfo.videoId是否有值，调用点播的不同接口获取uploadauth和uploadAddress
            // 如果 uploadInfo.videoId 有值，调用刷新视频上传凭证接口，否则调用创建视频上传凭证接口
            // 注意: 这里是测试 demo 所以直接调用了获取 UploadAuth 的测试接口, 用户在使用时需要判断 uploadInfo.videoId 存在与否从而调用 openApi
            // 如果 uploadInfo.videoId 存在, 调用 刷新视频上传凭证接口(https://help.aliyun.com/document_detail/55408.html)
            // 如果 uploadInfo.videoId 不存在,调用 获取视频上传地址和凭证接口(https://help.aliyun.com/document_detail/55407.html)
            if (!uploadInfo.videoId) {
                $.getJSON('{:url("Sellervideo/getAliyunCreateToken")}?file_name=' + uploadInfo.file.name, function (res) {
                    var data = res.result
                    var uploadAuth = data.UploadAuth
                    var uploadAddress = data.UploadAddress
                    var videoId = data.VideoId
                    uploader.setUploadAuthAndAddress(uploadInfo, uploadAuth, uploadAddress, videoId)
                })
            } else {
                // 如果videoId有值，根据videoId刷新上传凭证
                // https://help.aliyun.com/document_detail/55408.html?spm=a2c4g.11186623.6.630.BoYYcY
                $.getJSON('{:url("Sellervideo/getAliyunRefreshToken")}?video_id=' + uploadInfo.videoId, function (res) {
                    var data = res.result
                    var uploadAuth = data.UploadAuth
                    var uploadAddress = data.UploadAddress
                    var videoId = data.VideoId
                    uploader.setUploadAuthAndAddress(uploadInfo, uploadAuth, uploadAddress, videoId)
                })
            }
        },
        // 文件上传成功
        onUploadSucceed: function (uploadInfo) {
            save_video({
                video_type: 'aliyun',
                file_id: uploadInfo.videoId,
                file_name:fileInfo.name,
                size:fileInfo.size,
                url: uploadInfo.object,
                type: "{$Request.param.type}",
                item_id: "{$Request.param.item_id}"
            })
        },
        // 文件上传失败
        onUploadFailed: function (uploadInfo, code, message) {
            layer.msg(uploadInfo.file.name + message)
        },
        // 取消文件上传
        onUploadCanceled: function (uploadInfo, code, message) {
        },
        // 文件上传进度，单位：字节, 可以在这个函数中拿到上传进度并显示在页面上
        onUploadProgress: function (uploadInfo, totalSize, progress) {
            var progressPercent = Math.ceil(progress * 100)
            layer.close(index)
            index = layer.msg(progressPercent + '%', {
                icon: 16
            })
        },
        // 上传凭证超时
        onUploadTokenExpired: function (uploadInfo) {
            // 上传大文件超时, 如果是上传方式一即根据 UploadAuth 上传时
            // 需要根据 uploadInfo.videoId 调用刷新视频上传凭证接口(https://help.aliyun.com/document_detail/55408.html)重新获取 UploadAuth
            // 然后调用 resumeUploadWithAuth 方法, 这里是测试接口, 所以我直接获取了 UploadAuth

            $.getJSON('{:url("Sellervideo/getAliyunRefreshToken")}?video_id=' + uploadInfo.videoId, function (res) {
                var data = res.result
                var uploadAuth = data.UploadAuth
                uploader.resumeUploadWithAuth(uploadAuth)
            })
        },
        // 全部文件上传结束
        onUploadEnd: function (uploadInfo) {
        }
    })
    /*{/if}*/


    function selectCourseClass(goodscourses_class_id, goodscourses_class_name) {
        $('#goodscourses_class_name').val(goodscourses_class_name).show()
        $('#goodscourses_class_id').val(goodscourses_class_id)
        $('#cancle_goodscourses').show()
        $('#select_directory').hide();
    }
    function cancleCourseClas() {
        $('#goodscourses_class_name').val('').hide()
        $('#goodscourses_class_id').val('')
        $('#cancle_goodscourses').hide()
        $('#select_directory').show();
    }
    function goCheck(file_id, file_name) {
        if ($('.courseware-item[data-id="' + file_id + '"]').length) {
            return
        }
        $('#courseware_change').val(1)
        $('#check_courseware').append('<a class="courseware-item" data-id="' + file_id + '" href="javascript:delCheck(\'' + file_id + '\')">' + file_name + '<span class="iconfont">&#xe6e6;</span><input type="hidden" name="pand_id[' + file_id + ']" value="' + file_name + '"></a>')
    }
    function delCheck(file_id) {
        $('#courseware_change').val(0)
        $('.courseware-item[data-id="' + file_id + '"]').remove()
    }
</script>

{/block}

